//
//  FirstTouchHeaderView.m
//  EMMApp
//
//  Created by 无常先生 on 2018/8/20.
//  Copyright © 2018年 YiXun. All rights reserved.
//

#import "FirstTouchHeaderView.h"
#import "CustomerList.h"
@interface FirstTouchHeaderView ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *starImage;
@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
@property (weak, nonatomic) IBOutlet UILabel *gradeLabel;
@property (weak, nonatomic) IBOutlet UILabel *comInType;
@property (weak, nonatomic) IBOutlet UILabel *signLable;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumberLable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nameWidthConst;


@end

@implementation FirstTouchHeaderView

+ (instancetype)loadView {
    
    FirstTouchHeaderView *view = [[NSBundle mainBundle]loadNibNamed:@"FirstTouchHeaderView" owner:nil options:nil].lastObject;
    view.frame = CGRectMake(0, 0, EMM_WIDTH, 210);
    return view;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.sexLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    self.sexLabel.textColor = [UIColor whiteColor];
   
    
    self.gradeLabel.backgroundColor = [UIColor colorFromHexCode:@"#FB5A3B"];
    self.gradeLabel.textColor = [UIColor whiteColor];
   
    
}

- (void)setUserModel:(CustomerList *)userModel {
    _userModel = userModel;
    self.nameLabel.text = userModel.customerName;
    self.starImage.hidden = ![userModel.star isEqualToString:@"1"];
    NSString *sex = [userModel.customerSex isEqualToString:@"1"] ? @"男" : @"女";
    self.sexLabel.text =  [NSString stringWithFormat:@"   %@   ",sex];
    self.gradeLabel.text = [NSString stringWithFormat:@"   %@    ",userModel.intentionLevel];
    self.comInType.text = userModel.customerOrigin;
    self.signLable.text = userModel.customerStatus;
    self.phoneNumberLable.text = userModel.mobile;
    
     self.sexLabel.layer.cornerRadius = 5;
     [self.sexLabel.layer setMasksToBounds:YES];
     self.gradeLabel.layer.cornerRadius = 5;
    [self.gradeLabel.layer setMasksToBounds:YES];
    //
    if (!userModel.customerName.length) return;

    CGFloat width = self.frame.size.width - 180;
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
    CGSize textSize = [userModel.customerName boundingRectWithSize:self.frame.size options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    if (textSize.width > width ) {
        self.nameWidthConst.constant = width;
    }else {
        self.nameWidthConst.constant = textSize.width + 10;
    }
    
}

@end
